<html>
<head><meta charset="utf-8"><title>CLIPPY_ARGS is not tracked by Cargo · clippy · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/index.html">clippy</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html">CLIPPY_ARGS is not tracked by Cargo</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="228583111"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228583111" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228583111">(Mar 03 2021 at 12:32)</a>:</h4>
<p>It seems a <a href="https://github.com/rust-lang/rust-clippy/issues#allowingdenying-lints">known issue</a> that changing the arguments after <code>--</code> does not make Cargo re-check the crate:</p>
<blockquote>
<p>Note that if you've run clippy before, this may only take effect after you've modified a file or ran <code>cargo clean</code>.</p>
</blockquote>
<div class="codehilite" data-code-language="Bash Session"><pre><span></span><code><span class="gp">$</span> cargo new --vcs none clippy-args --lib
<span class="go">     Created library `clippy-args` package</span>
<span class="gp">$</span> <span class="nb">cd</span> clippy-args
<span class="gp">$</span> cargo clippy --tests -- -Aclippy::eq_op
<span class="go">    Checking clippy-args v0.1.0</span>
<span class="go">    Finished dev [unoptimized + debuginfo] target(s) in 0.59s</span>
<span class="gp">$</span> cargo clippy --tests -- -Fclippy::eq_op
<span class="go">    Finished dev [unoptimized + debuginfo] target(s) in 0.00s</span>
</code></pre></div>
<p>After some digging, I found that the arguments after <code>--</code> are passed by <code>CLIPPY_ARGS</code> environment variable, but Clippy does not do anything to make Cargo aware of that:</p>
<div class="codehilite" data-code-language="Bash Session"><pre><span></span><code><span class="gp">$</span> rg -F CLIPPY_ARGS
<span class="go">src/driver.rs</span>
<span class="go">280:        let clippy_args = env::var("CLIPPY_ARGS")</span>

<span class="go">src/main.rs</span>
<span class="go">151:            .env("CLIPPY_ARGS", clippy_args)</span>
</code></pre></div>
<p><a href="https://github.com/rust-lang/rust-clippy/issues/6441">clippy#6441</a> attempted to fix this, but it then got <a href="https://github.com/rust-lang/rust-clippy/pull/6498">reverted</a>. (I can't find the reason of reverting but <a href="https://github.com/rust-lang/rust-clippy/issues/6441">clippy#6441</a> seems unpractical anyway -- <code>RUSTFLAGS</code> applies to <em>all dependencies</em> and <a href="https://github.com/rust-lang/cargo/issues/4423">has no effect to procedural macro crates and build scripts when cross checking</a>. )</p>
<p>Currently there's no GitHub issue tracking this. Is there any blocker for fixing this or it's just low-priority? I can imagine Clippy doing something that <code>env!("CLIPPY_ARGS")</code> does to inform Cargo to track the environment variable.</p>



<a name="228584508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228584508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> flip1995 <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228584508">(Mar 03 2021 at 12:43)</a>:</h4>
<p>There was a problem with this, but I can't remember what it was. <span class="user-mention" data-user-id="279272">@Eduardo Broto</span> do you remember why we reverted this?</p>
<p>The reason this wasn't fixed yet is that no one has put time into it.</p>



<a name="228585158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228585158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228585158">(Mar 03 2021 at 12:48)</a>:</h4>
<blockquote>
<p>The reason this wasn't fixed yet is that no one has put time into it.</p>
</blockquote>
<p>Thanks for your response! I understand that as long as no one (at least I don't) specifies or changes the arguments after <code>--</code> <em>very often</em>, this is not very important, so probably not high-priority.</p>



<a name="228589160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228589160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eduardo Broto <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228589160">(Mar 03 2021 at 13:19)</a>:</h4>
<p>The reason it was reverted is because it was a bad approach as noted above. Changing RUSTFLAGS was rebuilding all the crates all the time.</p>
<p>IIRC the problem is that cargo does not notice the new flags, and there's no good way currently to change this. AFAIU this would require a change in cargo.</p>



<a name="228599088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228599088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228599088">(Mar 03 2021 at 14:21)</a>:</h4>
<p>I think this works:</p>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code><span class="gh">diff --git a/src/driver.rs b/src/driver.rs</span>
<span class="gh">index d5143e143..d2d35632e 100644</span>
<span class="gd">--- a/src/driver.rs</span>
<span class="gi">+++ b/src/driver.rs</span>
<span class="gu">@@ -11,8 +11,10 @@</span>
 extern crate rustc_driver;
 extern crate rustc_errors;
 extern crate rustc_interface;
<span class="gi">+extern crate rustc_span;</span>

 use rustc_interface::interface;
<span class="gi">+use rustc_span::symbol::Symbol;</span>
 use rustc_tools_util::VersionInfo;

 use std::borrow::Cow;
<span class="gu">@@ -73,6 +75,11 @@ impl rustc_driver::Callbacks for ClippyCallbacks {</span>
                 (previous)(sess, lint_store);
             }

<span class="gi">+            sess.parse_sess.env_depinfo.borrow_mut().insert((</span>
<span class="gi">+                Symbol::intern("CLIPPY_ARGS"),</span>
<span class="gi">+                env::var("CLIPPY_ARGS").ok().map(|args| Symbol::intern(&amp;args)),</span>
<span class="gi">+            ));</span>
<span class="gi">+</span>
             let conf = clippy_lints::read_conf(&amp;[], &amp;sess);
             clippy_lints::register_plugins(&amp;mut lint_store, &amp;sess, &amp;conf);
             clippy_lints::register_pre_expansion_lints(&amp;mut lint_store);
</code></pre></div>
<p>At least the output of <code>--emit=dep-info</code> contains <code>CLIPPY_ARGS</code>:</p>
<div class="codehilite" data-code-language="Bash Session"><pre><span></span><code><span class="gp">$</span> cargo run --bin clippy-driver --release -- --emit<span class="o">=</span>dep-info /dev/null -o /dev/stdout
<span class="go">    Finished release [optimized] target(s) in 0.04s</span>
<span class="go">     Running `target/release/clippy-driver --emit=dep-info /dev/null -o /dev/stdout`</span>
<span class="go">/dev/stdout: /dev/null</span>

<span class="go">/dev/null:</span>

<span class="gp">#</span> env-dep:CLIPPY_ARGS
<span class="gp">$</span> <span class="nv">CLIPPY_ARGS</span><span class="o">=</span><span class="s1">'-Aclippy::all'</span> cargo run --bin clippy-driver --release -- --emit<span class="o">=</span>dep-info /dev/null -o /dev/stdout
<span class="go">    Finished release [optimized] target(s) in 0.04s</span>
<span class="go">     Running `target/release/clippy-driver --emit=dep-info /dev/null -o /dev/stdout`</span>
<span class="go">/dev/stdout: /dev/null</span>

<span class="go">/dev/null:</span>

<span class="gp">#</span> env-dep:CLIPPY_ARGS<span class="o">=</span>-Aclippy::all
</code></pre></div>



<a name="228603221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228603221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228603221">(Mar 03 2021 at 14:44)</a>:</h4>
<p>Oh that is super helpful</p>



<a name="228603270"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228603270" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228603270">(Mar 03 2021 at 14:44)</a>:</h4>
<p>I can finally fix the issues with RUSTDOC_LOG not rebuilding lol</p>



<a name="228616067"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228616067" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228616067">(Mar 03 2021 at 15:56)</a>:</h4>
<p>hmm, I tried to do this automatically, but I don't have a <code>ParseSess</code> available early enough:</p>
<div class="codehilite"><pre><span></span><code>error[E0061]: this function takes 1 argument but 0 arguments were supplied
    --&gt; compiler/rustc_driver/src/lib.rs:1316:5
     |
1316 |     init_rustc_env_logger();
     |     ^^^^^^^^^^^^^^^^^^^^^-- supplied 0 arguments
     |     |
     |     expected 1 argument
</code></pre></div>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="o">!</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">start_time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Instant</span>::<span class="n">now</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">start_rss</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get_resident_set_size</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="n">init_rustc_env_logger</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="c1">// ...</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="228618485"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228618485" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228618485">(Mar 03 2021 at 16:10)</a>:</h4>
<p>Clippy doesn't have <code>ParseSess</code> when using <code>CLIPPY_ARGS</code> too. In the patch I posted, I access <code>ParseSess</code> in the <code>Config::register_lints</code>callback (probably not the best place, but I can't find a better one), <em>after</em> <code>CLIPPY_ARGS</code> is used.</p>



<a name="228619405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228619405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228619405">(Mar 03 2021 at 16:14)</a>:</h4>
<p>my current idea is to make the env variable part of <code>options::Config</code> and register it automatically when the session is constructed</p>



<a name="228619443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228619443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228619443">(Mar 03 2021 at 16:15)</a>:</h4>
<p>that doesn't help CLIPPY_ARGS but it sounds like you have that working anyway</p>



<a name="228624250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228624250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228624250">(Mar 03 2021 at 16:42)</a>:</h4>
<p><a href="https://github.com/rust-lang/cargo/issues/8374#issuecomment-789861761">https://github.com/rust-lang/cargo/issues/8374#issuecomment-789861761</a></p>



<a name="228646362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257328-clippy/topic/CLIPPY_ARGS%20is%20not%20tracked%20by%20Cargo/near/228646362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> hyd-dev <a href="https://rust-lang.github.io/zulip_archive/stream/257328-clippy/topic/CLIPPY_ARGS.20is.20not.20tracked.20by.20Cargo.html#228646362">(Mar 03 2021 at 18:53)</a>:</h4>
<p>/me submitted <a href="https://github.com/rust-lang/rust-clippy/issues/6834">clippy#6834</a>.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>